package com.ysw.constant;

/**
 * @ClassName ServiceCodeStatus 业务状态枚举
 * @Description 提供获取状态码及描述异常描述
 * @Author ysw
 * @Date 2022/5/12 17:22
 */
public enum ServiceCodeStatus implements ICodeStatus{
    /**
     * 成功
     */
    SUCCESS("200","OK"),
    BASE_VALID_PARAM("401","params is error"),
    /**
     * 失败
     */
    ERROR("500","something is error"),
    /**
     * 请求失败
     */
    BAD_REQUEST("400","request error"),
    REPEAT_REQUEST("401","repeat request"),
    UNDEFINED("4001", "unknow source");
    private final String code;

    private final String reasonPhrase;

    ServiceCodeStatus(String code, String reasonPhrase) {
        this.code = code;
        this.reasonPhrase = reasonPhrase;
    }

    @Override
    public String getCode() {
        return this.code;
    }

    @Override
    public String getReasonPhrase() {
        return this.reasonPhrase;
    }

    @Override
    public String toString() {
        return code;
    }

    /**
     * 暴露对外获取枚举方法
     * @param statusCode
     * @return
     */
    public static ServiceCodeStatus getCodeStatus(String statusCode) {
        for (ServiceCodeStatus status : values()) {
            if (status.code.equals(statusCode)) {
                return status;
            }
        }
        return ServiceCodeStatus.UNDEFINED;
    }
}
